package javachongkao.面向对象下.NCHU_图形继承与多态;

import java.util.*;

//7-20 NCHU_图形继承与多态
//掌握类的继承、多态性及其使用方法。具体需求参见作业指导书。
//
//2021-OO第06次作业-5指导书V1.0.pdf
//
//输入格式:
//从键盘首先输入三个整型值（例如a b c），分别代表想要创建的Circle、Rectangle及Triangle对象的数量，然后根据图形数量继续输入各对象的属性值（均为实型数），数与数之间可以用一个或多个空格或回车分隔。
//
//输出格式:
//如果图形数量非法（小于0）或图形属性值非法（数值小于0以及三角形三边关系），则输出Wrong Format。
//如果输入合法，则正常输出，输出内容如下（输出格式见输入输出示例）：
//各个图形的面积；
//所有图形的面积总和；
//排序后的各个图形面积；
//再次所有图形的面积总和。
abstract class Shape {
    public abstract double getArea();
}

class Circle extends Shape {
    private double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    @Override
    public double getArea() {
        return Math.PI * radius * radius;
    }
}

class Rectangle extends Shape {
    private double width;
    private double length;

    public Rectangle(double width, double length) {
        this.width = width;
        this.length = length;
    }

    @Override
    public double getArea() {
        return width * length;
    }
}

class Triangle extends Shape {
    private double a;
    private double b;
    private double c;

    public Triangle(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    @Override
    public double getArea() {
        double s = (a + b + c) / 2;
        return Math.sqrt(s * (s - a) * (s - b) * (s - c));
    }

    public static boolean isValid(double a, double b, double c) {
        return a > 0 && b > 0 && c > 0 &&
                a + b > c && a + c > b && b + c > a;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        try {
            int circleCount = scanner.nextInt();
            int rectangleCount = scanner.nextInt();
            int triangleCount = scanner.nextInt();

            // 检查图形数量是否合法
            if (circleCount < 0 || rectangleCount < 0 || triangleCount < 0) {
                System.out.println("Wrong Format");
                return;
            }

            List<Shape> shapes = new ArrayList<>();

            // 读取并创建圆形对象
            for (int i = 0; i < circleCount; i++) {
                double radius = scanner.nextDouble();
                if (radius <= 0) {
                    System.out.println("Wrong Format");
                    return;
                }
                shapes.add(new Circle(radius));
            }

            // 读取并创建矩形对象
            for (int i = 0; i < rectangleCount; i++) {
                double width = scanner.nextDouble();
                double length = scanner.nextDouble();
                if (width <= 0 || length <= 0) {
                    System.out.println("Wrong Format");
                    return;
                }
                shapes.add(new Rectangle(width, length));
            }

            // 读取并创建三角形对象
            for (int i = 0; i < triangleCount; i++) {
                double a = scanner.nextDouble();
                double b = scanner.nextDouble();
                double c = scanner.nextDouble();
                if (!Triangle.isValid(a, b, c)) {
                    System.out.println("Wrong Format");
                    return;
                }
                shapes.add(new Triangle(a, b, c));
            }

            // 输出原始面积
            System.out.print("Original area:\n");
            double totalArea = 0;
            for (Shape shape : shapes) {
                double area = shape.getArea();
                System.out.printf("%.2f ", area);
                totalArea += area;
            }
            System.out.println();

            // 输出总面积
            System.out.printf("Sum of area:%.2f\n", totalArea);

            // 排序
            shapes.sort(Comparator.comparingDouble(Shape::getArea));

            // 输出排序后面积
            System.out.print("Sorted area:\n");
            totalArea = 0;
            for (Shape shape : shapes) {
                double area = shape.getArea();
                System.out.printf("%.2f ", area);
                totalArea += area;
            }
            System.out.println();

            // 再次输出总面积
            System.out.printf("Sum of area:%.2f\n", totalArea);

        } catch (Exception e) {
            System.out.println("Wrong Format");
        }
    }
}
